package com.egu.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.egu.model.TbClass;
import com.egu.service.ClassService;
import com.egu.vo.PageParam;
import com.egu.vo.RequestPageVo;
import com.egu.vo.RequestResultVo;

@Controller
@RequestMapping("class")
public class ClassController {

	@Autowired
	private ClassService classService;

	@RequestMapping("listUI")
	public String listUI() {
		return "class/listUI";
	}

	@RequestMapping("/getList")
	@ResponseBody
	public RequestPageVo<TbClass> getList(@ModelAttribute(value = "param") PageParam param, TbClass tbClass) {
		RequestPageVo<TbClass> vo = classService.getList(param, tbClass);
		return vo;
	}

	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public RequestResultVo<TbClass> saveOrUpdate(TbClass tbClass) {
		RequestResultVo<TbClass> result = new RequestResultVo<TbClass>();
		if (tbClass != null) {
			return classService.saveOrUpdate(tbClass);
		} else {
			result.setSuccess(false);
		}
		return result;
	}

	@RequestMapping("/deleteDataById")
	public @ResponseBody RequestResultVo<TbClass> deleteDataById(@RequestParam(value = "id", required = false) Integer id) {
		RequestResultVo<TbClass> result = new RequestResultVo<TbClass>();
		if (id == null) {
			result.setSuccess(false);
			result.setErrorMessage("数据库操作异常");
			return result;
		}
		result = classService.deleteDataById(id);
		return result;
	}

}
